/**
 * 
 */

(function($) {
	var str = '<h3 class="analyse_h3_header">成绩报告</h3><select class="default"></select><div class="the_show">'
		    +'<h3 class="the_show_header"></h3>'
			+ '<div  class="lcharts_content" ><div class="cost_pie" ></div><div class="describe_left style1"></div></div><div class="rcharts_content"><div class="cost_rank" '
			+ '></div><div class="describe_right style1"></div></div></div>';
	$('div.charts_right').css({'background':'white','border':'1px solid #d2d2d2'}).append(str);
	var the_str = ' <h3>课程通过率分析</h3>' + '<ul>'
			+ '<li><span>0 ~ 20%</span> <span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span></li>'
			+ '<li><span>20% ~ 40%</span> <span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span></li>'
			+ '<li><span>40% ~ 60%</span> <span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span></li>'
			+ '<li><span>60% ~ 80%</span> <span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span></li>'
			+ '<li><span>80% ~ 100%</span> <span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span><span class="blue_span"></span></li></ul>';
	
			$.getJSON(
					'/WDDXSERVER/home/getCJForPcDefault?callback=?',
					{
						userid : user_id,ticket:ticket
					}, function(data) {
						var $select = $('div.charts_right select');
						var str = [];
						data = data.content.message.items;
						var length = data.length;
						for (var i = 0; i < length; i++)
							str[i] = ' <option value="' + data[i].rm_xq + '">' + data[i].xnxq + '</option>';
						$select.append(str.join(''));
						$select.dropkick({
							change : function(value, label) {
								paint_right({
									userid : user_id,
									rm_xq : value,
									ticket : ticket
								});
							}
						});
						paint_right({
							userid : user_id,
							rm_xq : data[0].rm_xq,
							ticket : ticket
						});
					});
	function paint_right(param) {
		$('div.the_show').find('div.cost_pie').empty();
		$('div.the_show').find('div.describe_left').empty();
		$('div.the_show').find('div.cost_rank').empty();
		$('div.the_show').find('div.describe_right').empty();
		$.getJSON(
						'/WDDXSERVER/report/getScores?callback=?',
						param,
						function(data) {
							var c1 = echarts.init($('div.cost_pie')[0], 'macarons');
							c1.hideLoading();
							var option1 = Config('各课成绩分布情况', '分', '科').option2(
									data.pie_data);
							c1.setOption(option1, true);
							$('div.cost_rank ').append(the_str);
							$('div.cost_rank span').css('display',
									'inline-block');
							$('div.the_show h3.the_show_header').text('本学期课程通过率'+data.ranking);
							if(data.pm!='100%'&&data.pm!='0%'){
							  var the_rank = parseInt(parseInt(data.pm) / 4);
							  var the_rank_sy = parseInt(data.pm) % 4;
							  if(the_rank_sy!=0)
								  the_rank=the_rank+1;
							  var the_rank_detial,the_rank_detial_sy;
							  the_rank_detial = parseInt(the_rank / 5);
								 the_rank_detial_sy=the_rank % 5;
								 if(the_rank_detial_sy==0)
								   $('div.cost_rank ul li:eq('+(the_rank_detial-1)+') span.blue_span:eq(4)').
								     removeClass('blue_span').addClass('red_span');
								 else
									$('div.cost_rank ul li:eq('+the_rank_detial+') span.blue_span:eq('+(the_rank_detial_sy-1)+')').
								    removeClass('blue_span').addClass('red_span');
							   }
							else if(data.pm=='0%')
								$('div.cost_rank ul li:eq(0) span.blue_span:eq(0)').
							    removeClass('blue_span').addClass('red_span');
							else if(data.pm=='100%')
								$('div.cost_rank ul li:eq(4) span.blue_span:eq(4)').
							    removeClass('blue_span').addClass('red_span');
							$('div.describe_left').append('<h3>你的成绩情况分析总结</h3><p>'+data.describe[0]+'</p>');
							$('div.describe_right').append('<h3>你的课程通过率高于全校'+data.pm+'的学生</h3><p>'+data.describe[0]+'</p>');
							$(window).resize(function() {
								c1.resize();
								c1.setOption(option1);
							});
						});
	}
})(jQuery);